using System;
using System.Collections.Generic;
using System.Text;
using EnvDTE80;
using EnvDTE;
using Microsoft.VisualStudio.Modeling;
using Microsoft.VisualStudio.OLE.Interop;
using Microsoft.VisualStudio.Modeling.Shell;
using DslFactory.Utilities.DteCodeModel;

namespace DslFactory.Utilities.DragDrop
{
 /// <summary>
 /// Utility to process Drag &amp; Drop from the Class View
 /// </summary>
 public static class DragDropFromClassView
 {
  /// <summary>
  /// Get the dropped CodeTypes.
  /// </summary>
  public static IEnumerable<CodeType> GetDroppedCodeTypes(Store store, System.Windows.Forms.IDataObject data)
  {
   ClassViewNavigationInfoNode[] nodes = ClassViewNavigationInfo.GetData(data);
   KnownCodeTypes knownCodeTypes = KnownCodeTypes.FromStore(store);
   bool useProjectName = (knownCodeTypes==null);
   foreach (ClassViewNavigationInfoNode node in nodes)
   {
    string nodeFullName = node.FullName;

    // Special case of a model which is in the solution, but not in a project !
    if (useProjectName)
     knownCodeTypes = KnownCodeTypes.FromStoreAndProjectName(store, node.ProjectName);

    switch (node.InfoType)
    {
     case ClassViewNavigationInfoTypes.Class:
      CodeType codeType = knownCodeTypes.GetFullNamedType(nodeFullName);
      if (codeType != null)
       yield return codeType;
      break;

     case ClassViewNavigationInfoTypes.Namespace:
      foreach (CodeType aCodeType in knownCodeTypes.GetAllKnownTypes())
       if (aCodeType.Namespace.FullName == nodeFullName)
        yield return aCodeType;
      break;

     case ClassViewNavigationInfoTypes.Project:
      // TODO:
      break;
     default:
      break;
    }
   }
  }


 }
}
